<?php
/**
 * @author tungck
 * @filesource contract.php
 * quan ly loai hop dong 
*/

class Contract extends CI_Controller{
    
    function __construct(){
        
        parent::__construct();
        $this->load->helper('url');
        $this->load->library(array('form_validation','session'));
        $this->load->library('adminlayout');
        $this->adminlayout->setLayout("admin/layout");
        
        $userSession = $this->session->userdata('user');
        
        if($userSession['username'] == false){
            redirect(base_url('/index/login?returnUrl=').urlencode(RETURN_URL));
            
        }else{
            if($userSession['useradmin'] != 1){
                redirect(base_url('nhanvien/event/list_event'));
            }
        }
    }
    
    function listContract(){
        $title = "Danh sách hồ sơ nhân viên";
        $this->adminlayout->view("admin/listContract",null ,$title);        
    }
    
    function getListContract(){
        try{
        $data['sort'] = $_GET["jtSorting"];
        $data['startIndex'] = $_GET["jtStartIndex"];
        $data['pageSize'] = $_GET["jtPageSize"];
        $this->load->model("admin/contract_model");
        $result = $this->contract_model->getList($data);
        $jTableResult = array();
		$jTableResult['Result'] = "OK";
        $jTableResult['TotalRecordCount'] = $result['recordCount'];
		$jTableResult['Records'] = $result['query'];
		print json_encode($jTableResult);
        }catch(Exception $ex){
            $jTableResult['Result'] = "ERROR";
            $jTableResult['Records'] = 'afhkahfkafhkahfakfhka';
            print json_encode($jTableResult);
        }
    }
    
    
    function addContract(){
        $jTableResult = array();
        if(!empty($_POST['TenLoaiHopDong'])){
            $data['TenLoaiHopDong'] = $_POST['TenLoaiHopDong'];
            $this->load->model("admin/contract_model");
            $result = $this->contract_model->insertContract($data);
            $jTableResult['Result'] = "OK";
            $jTableResult['Record'] = $result;
            print json_encode($jTableResult);
        }else{
            $jTableResult['Result'] = "ERROR";
            $jTableResult['Message'] = array('Nhập Tên Loại Hợp Đồng');
   	        print json_encode($jTableResult);
        }
    }
    
    function deleteContract(){
        try{
        if(isset($_POST["MaLoaiHopDong"])){
            $id = $_POST["MaLoaiHopDong"];
            $this->load->model("admin/contract_model");
            $this->contract_model->deleteContract($id);
            $jTableResult = array();
            $jTableResult['Result'] = "OK";
            print json_encode($jTableResult);
            
        }
        }catch(Exception $ex){
            $jTableResult = array();
	        $jTableResult['Result'] = "ERROR";
	           $jTableResult['Message'] = $ex->message();
    	       print json_encode($jTableResult);
        }
        
    }
    
    function updateContract(){
        $jTableResult = array();
        if(!empty($_POST['TenLoaiHopDong'])){
            $data['MaLoaiHopDong'] = $_POST['MaLoaiHopDong'];
            $data['TenLoaiHopDong'] = $_POST['TenLoaiHopDong'];
            $this->load->model("admin/contract_model");
            $this->contract_model->updateContract($data);
            $jTableResult['Result'] = "OK";
            print json_encode($jTableResult);
        }else{
            $jTableResult['Result'] = "ERROR";
            $jTableResult['Message'] = array('Nhập Tên Loại Hợp Đồng');
   	        print json_encode($jTableResult);
        }
    }
    
}

?>